<?php

  function randString($num_require=16) {
    $alphanumeric = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',0,1,2,3,4,5,6,7,8,9);
    if($num_require > sizeof($alphanumeric)){
      echo "Error randString(\$num_require) : \$num_require must less than " . sizeof($alphanumeric) . ", $num_require given";
      return;
    }
    $rand_key = array_rand($alphanumeric , $num_require);
    $randomstring = '';
    for($i=0;$i<sizeof($rand_key);$i++) {
      $randomstring .= $alphanumeric[$rand_key[$i]];
    }
    return $randomstring;
  }

  function arrayLanguage() {
    $currentUrl = Yii::app()->request->getUrl();
    if($currentUrl=='/') {
      $currentUrl = '/'. Yii::app()->language .'/site/index/';
    }

    $pattern = '/'. Yii::app()->language .'/';

    echo CHtml::link(CHtml::image(Yii::app()->request->baseUrl.'/images/icons/icon_flagTH.jpg'). 'THA', str_replace($pattern, '/th/', $currentUrl));
    echo CHtml::link(CHtml::image(Yii::app()->request->baseUrl.'/images/icons/icon_flagEN.jpg'). 'ENG', str_replace($pattern, '/en/', $currentUrl));
  }

  function getConfig($name) {
    $ret = Config::model()->find(array('condition'=>'name="'.$name.'"'));
    return empty($ret) ? null : $ret->data;
  }

